package baiduPic;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;

public class PageUrl {

	private String queryWord;
	private int pn;
	private String gsm;

	public PageUrl(String queryWord, int pn) {
		// 对查询关键字进行url编码
		try {
			this.queryWord = URLEncoder.encode(queryWord, "GBK");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		this.pn = pn;
		this.gsm = Integer.toHexString(pn);
	}

	// pn 和 gsm 应该是一起变化的
	public void setPn(int pn) {
		this.pn = pn;
		this.gsm = Integer.toHexString(pn);
	}

	@Override
	public String toString() {
		return "https://image.baidu.com/search/acjson?tn=resulttagjson&logid=8289309082224849732&ie=utf-8&fr=&word="
							 + queryWord + "&ipn=r&fm=index&pos=history&queryWord="
							 + queryWord + "&cl=2&lm=-1&oe=utf-8&adpicid=&st=-1&z=&ic=&hd=&latest=0&copyright=0&s=&se=&tab=&width=1920&height=1080&face=0&istype=2&qc=&nc=1&expermode=&nojc=&isAsync=true&pn="
							 + pn+ "&rn=30&gsm=" + gsm + "&" + new Date().getTime() + "=";
	}
	//https://image.baidu.com/search/acjson?tn=resulttagjson&logid=8289309082224849732&ie=utf-8&fr=&word=
	// windows%E6%A1%8C%E9%9D%A2%E8%83%8C%E6%99%AF&ipn=r&fm=index&pos=history&queryWord=windows%E6%A1%8C%E9%9D%A2%E8%83%8C%E6%99%AF
	// &cl=2&lm=-1&oe=utf-8&adpicid=&st=-1&z=&ic=&hd=&latest=0&copyright=0&s=&se=&tab=&width=1920&height=1080&face=0&istype=2&qc=&nc=1&expermode=&nojc=&isAsync=true
	// &pn=60&rn=30&itg=1&gsm=3c&1653218735448=
}